import 'package:boss/models/analysis_detail.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/analysis/page/analysisDetail/model/analysis_detail_type.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flustars/flustars.dart' as flustars;

class TableRow extends StatelessWidget {
  final AnalysisDetailItem data;
  final AnalysisDetailType type;

  const TableRow(this.data, this.type);

  @override
  Widget build(BuildContext context) {
    String time;
    try {
      time = flustars.DateUtil.formatDate(DateTime.parse(data.time), format: flustars.DateFormats.mo_d);
    } catch (e) {}

    return DefaultTextStyle(
      style: TextStyleConstant().normal_1_28,
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
      child: Container(
        height: 80.w,
        child: Row(
          children: <Widget>[
            if (type == AnalysisDetailType.takeoutSellSort) ..._buildTakeoutSellSort(time),
            if (type == AnalysisDetailType.commodityCommissionSort) ..._buildCommodityCommissionSort(time),
            if (type == AnalysisDetailType.book) ...buildStaffBookList(),
          ],
        ),
      ),
    );
  }

  List<Widget> _buildTakeoutSellSort(String time) {
    return [
      Expanded(
        child: Container(
          child: Text('$time'),
          alignment: Alignment.center,
        ),
      ),
      Expanded(
        child: Container(
          child: Text('小费'),
          alignment: Alignment.center,
        ),
      ),
      Expanded(
        child: Container(
          child: Text('￥${AmountUtil.price2String(data.money)}'),
          alignment: Alignment.center,
        ),
        flex: 2,
      ),
      Expanded(
        child: Container(
          child: Text('${data.name}'),
          alignment: Alignment.center,
        ),
        flex: 2,
      ),
      Expanded(
        child: Container(
          child: Text(
            data.statusText,
            style: data.statusText == '待分账' ? TextStyleConstant().origin_28 : null,
          ),
          alignment: Alignment.center,
        ),
      ),
    ];
  }

  List<Widget> _buildCommodityCommissionSort(String time) {
    return [
      Expanded(
        child: Container(
          child: Text('$time'),
          alignment: Alignment.center,
        ),
      ),
      Expanded(
        child: Container(
          child: Text('￥${AmountUtil.price2String(data.money)}'),
          alignment: Alignment.center,
        ),
        flex: 2,
      ),
      Expanded(
        child: Container(
          child: Text('${data.name}'),
          alignment: Alignment.center,
        ),
        flex: 2,
      ),
      Expanded(
        child: Container(
          child: Text(
            data.statusText,
            style: data.statusText == '待分账' ? TextStyleConstant().origin_28 : null,
          ),
          alignment: Alignment.center,
        ),
      ),
    ];
  }

  List<Widget> buildStaffBookList() {
    return [
      Expanded(
        child: Container(
          child: Text('${data.name}'),
          alignment: Alignment.center,
        ),
      ),
      Expanded(
        child: Container(
          child: Text('${data.tableCount}'),
          alignment: Alignment.center,
        ),
      ),
      Expanded(
        child: Container(
          child: Text('¥${AmountUtil.price2String(data.money)}'),
          alignment: Alignment.center,
        ),
      ),
    ];
  }
}
